
<template>
  <!-- <div>
    <h1>天气预报</h1>
    <p v-if="weatherData">
      <strong>城市:</strong> {{ weatherData.province }}, {{ weatherData.city }}<br>
      <strong>温度:</strong> {{ Math.round(weatherData.temperature) }}°C<br>
      <strong>风向:</strong> {{ weatherData.winddirection }}<br>
      <strong>湿度:</strong> {{ weatherData.humidity }} %<br>
      <strong>天气:</strong> {{ weatherData.weather }}
    </p>
    <p v-else>加载中...</p>
  </div> -->
  
  <iframe scrolling="no" src="http://weather.seniverse.com/?token=6b84925e-be53-4743-8813-050db418a532" frameborder="0" style="width: 100%;height: 220px;" allowtransparency="true"></iframe>
</template>


<!-- <script>
import {
  getCityWeather
  } from "@/api/iot/device";
  import axios from 'axios';
 export default {
  data() {
            return {
              weatherData:{},
            };
          },
        created() {
          (function(a,h,g,f,e,d,c,b){b=function(){d=h.createElement(g);c=h.getElementsByTagName(g)[0];d.src=e;d.charset="utf-8";d.async=1;c.parentNode.insertBefore(d,c)};a["SeniverseWeatherWidgetObject"]=f;a[f]||(a[f]=function(){(a[f].q=a[f].q||[]).push(arguments)});a[f].l=+new Date();if(a.attachEvent){a.attachEvent("onload",b)}else{a.addEventListener("load",b,false)}}(window,document,"script","SeniverseWeatherWidget","//cdn.sencdn.com/widget2/static/js/bundle.js?t="+parseInt((new Date().getTime() / 100000000).toString(),10)));
  window.SeniverseWeatherWidget('show', {
    flavor: "slim",
    location: "WWC3FS39WJMP",
    geolocation: true,
    language: "zh-Hans",
    unit: "c",
    theme: "auto",
    token: "6b84925e-be53-4743-8813-050db418a532",
    hover: "enabled",
    container: "tp-weather-widget"
  })
        },
        beforeDestroy() {
            this.clearData()
        },
        methods: {
              // 获取天气
          getCityWeather(cityCode,key){
            
            const url = `https://restapi.amap.com/v3/weather/weatherInfo?city=${cityCode}&key=${key}`;
            
            axios.get(url).then(response => {
              
                if (response.data.status === "1") {
                  this.weatherData = response.data.lives[0];
                  console.log(this.weatherData)
                } else {
                  console.error("获取天气信息失败:", response.data.code);
                }
              })
              .catch(error => {
                console.error("请求发生错误:", error);
              });
          

          },
         
            clearData() {
                if (this.timer) {
                    clearInterval(this.timer)
                    this.timer = null
                }
            },
            //轮询
            switper() {
                if (this.timer) {
                    return
                }
                let looper = (a) => {
                    this.getCityWeather()
                };
                this.timer = setInterval(looper, 60000);
            },
        },
  };
 </script> -->
